import cv2
import numpy as np
img_path="orange.jpg"
img=cv2.imread(img_path)
cv2.imshow("Original",img)
imgHSV=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow("HSV",imgHSV)
def empty(obj):
    pass
cv2.namedWindow("TrackBars")
cv2.resizeWindow("TrackBars",640,240)
cv2.createTrackbar("Hue Min","TrackBars",0,180,empty)
cv2.createTrackbar("Hue Max","TrackBars",19,180,empty)
cv2.createTrackbar("Sat Min","TrackBars",134,255,empty)
cv2.createTrackbar("Sat Max","TrackBars",255,255,empty)
cv2.createTrackbar("Val Min","TrackBars",160,255,empty)
cv2.createTrackbar("Val Max","TrackBars",255,255,empty)
while True:
    h_min=cv2.getTrackbarPos('Hue Min','TrackBars')
    h_max = cv2.getTrackbarPos('Hue Min', 'TrackBars')
    s_min = cv2.getTrackbarPos('Hue Min', 'TrackBars')
    s_max = cv2.getTrackbarPos('Hue Min', 'TrackBars')
    v_min = cv2.getTrackbarPos('Hue Min', 'TrackBars')
    v_max = cv2.getTrackbarPos('Hue Min', 'TrackBars')
    h_max = cv2.getTrackbarPos('Hue Max', 'TrackBars')
    s_min = cv2.getTrackbarPos('Sat Min', 'TrackBars')
    s_max = cv2.getTrackbarPos('Sat Max', 'TrackBars')
    v_min = cv2.getTrackbarPos('Val Min', 'TrackBars')
    v_max = cv2.getTrackbarPos('Val Max', 'TrackBars')
    lower=np.array([[h_min],[s_min],[v_min]])
    upper = np.array([[h_max], [s_max], [v_max]])
    mask=cv2.inRange(imgHSV,lower,upper)
    cv2.imshow('Mask',mask)
    imgResult=cv2.bitwise_and(img,img,mask=mask)
    cv2.imshow('Result',imgResult)
    if cv2.waitKey(1)==ord('q'):
        break
cv2.destroyAllWindows()